package org.example.log;

import org.apache.commons.io.FileUtils;
import org.example.utlis.FXUtils;
import org.example.utlis.TimeUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

public class Log {
    private static final String PATH = "../../log";
    public static void saveLog(String newline) {
        new Thread(() -> {
            String currentDay = TimeUtils.getCurrentDay();
            String fileName = PATH + "/" + currentDay + ".txt";
            try {
                File file = new File(fileName);
                FileUtils.writeStringToFile(file, newline, Charset.defaultCharset(), true);
            } catch (IOException ex) {
                FXUtils.initSimpleDialog("日志写入出错！", ex.toString());
            }
        }).start();
    }
}
